var prefix = jsctx + "/hlhtTenantOpenApply";

var auditHlhtTenantOpenApply = (function () {
    function init() {
        validateRule();
    };

    function getCheckedRoles() {
        var adIds = "";
        $("input:checkbox[name=role]:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();
            } else {
                adIds += ("," + $(this).val());
            }
        });
        return adIds;
    }

    var isajaxsend = true;

    function save() {
        if (isajaxsend) {
             var formData = new FormData($("#frmAuditHlhtTenantOpenApply")[0]);
            $("#roleIds").val(getCheckedRoles());
            $.ajax({
                cache: true,
                type: "POST",
                url: prefix + "/insertTenantAndOperatorAndOpen",
                // data: $('#frmAuditHlhtTenantOpenApply').serialize(),
                data: formData,
                processData: false,
                contentType: false,
                async: false,
                beforeSend: function () {
                    isajaxsend = false
                },
                error: function (request) {
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.status == 200) {
                        parent.layer.msg("操作成功");
                        window.history.back();
                    } else {
                        parent.layer.alert(data.message)
                    }
                },
                complete: function () {
                    isajaxsend = false
                }
            });
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#frmAuditHlhtTenantOpenApply").validate({
            rules: {},
            messages: {},
            submitHandler: function (form) {
                save();
            }
        })
    }

    function goBack() {
        location.href = prefix + "/index";
    }

    return {
        init: init,
        goBack: goBack
    };
})();






